package xl.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xl.service.RAGService;


// AIController.java

import java.io.IOException;
import java.util.Collections;
import java.util.Map;

@RestController
@RequestMapping("/api/chat")
@RequiredArgsConstructor
public class ChatController {
    private final RAGService ragService;

    @PostMapping
    public ResponseEntity<Map<String, String>> chat(String request) {
        String answer = null;
        try {
            answer = ragService.answerQuestion(request);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return ResponseEntity.ok(Collections.singletonMap("answer", answer));
    }
}
